//
//  YLMemberHeader.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/11.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLMemberHeader.h"
#import <Masonry.h>
#import "YLProgressView.h"
#import "YLGlobeHeader.h"
#import "YLMemberLevelViewModel.h"
#import "YLMemberLevelModel.h"
#import <UIImageView+WebCache.h>
@interface YLMemberHeader ()
@property (nonatomic, weak) YLProgressView *progressView;

@property (nonatomic, strong) YLMemberLevelViewModel *viewModel;

@property (nonatomic, weak) UIImageView *memberImageView;

@property (nonatomic, weak) UILabel *showLabel;



@end

@implementation YLMemberHeader

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUp];
    }
    return self;
}

- (YLMemberLevelViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[YLMemberLevelViewModel alloc] init];
    }
    return _viewModel;
}


- (void)setUp
{
    __weak typeof(self) weakSelf = self;
    UIImageView *backgroundImageView = [[UIImageView alloc] init];
    backgroundImageView.image = [UIImage imageNamed:@"mineHeader"];
    [self addSubview:backgroundImageView];
    [backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(weakSelf);
    }];
    
    UIButton *profitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self addSubview:profitButton];
    [profitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [profitButton setTitle:@"在投年化金额" forState:UIControlStateNormal];
    profitButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
    [profitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf).mas_offset(-10);
        make.centerX.mas_equalTo(weakSelf);
        make.height.mas_equalTo(20);
    }];
    
    YLProgressView *progressView = [[YLProgressView alloc] init];
    _progressView = progressView;
    progressView.layer.masksToBounds = YES;
    progressView.layer.cornerRadius = YLWidth(10);
    [self addSubview:progressView];
    [progressView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf).mas_offset(35);
        make.right.mas_equalTo(weakSelf).mas_offset(-35);
        make.height.mas_equalTo(YLWidth(20));
        make.bottom.mas_equalTo(profitButton.mas_top).mas_equalTo(-5);
    }];
    
    UILabel *showLabel = [[UILabel alloc] init];
    _showLabel = showLabel;
    showLabel.textColor = YLLOrgColor;
    showLabel.font = [UIFont systemFontOfSize:11.0f];
    showLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:showLabel];
    [showLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.mas_equalTo(progressView);
    }];
    
    UIImageView *memberImageView = [[UIImageView alloc] init];
    _memberImageView = memberImageView;
    [self addSubview:memberImageView];
    [memberImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(weakSelf);
        make.top.mas_equalTo(weakSelf).mas_offset(15);
        make.bottom.mas_equalTo(weakSelf.progressView.mas_top).mas_offset(-15);
        make.width.mas_equalTo(memberImageView.mas_height);
    }];
    
    
    
}

- (void)setModel:(YLMemberLevelModel *)model
{
    _model = model;
    [_memberImageView sd_setImageWithURL:[NSURL URLWithString:model.levelIcon] placeholderImage:nil];
    
    _showLabel.text = model.showMoney;
    
    [_progressView setProgress:model.rateProgress];
    
}





+ (NSString *)headerID
{
    return @"YLMemberHeader";
}

@end
